﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

/* Author: Paweł Iżycki */
namespace Logging
{
    // Singleton
    public class Logger
    {
        #region Singleton
        private static Logger _instance = null;
        public static Logger Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new Logger();
                return _instance;
            }
        }
        #endregion

        public void PrintDate(bool endWithBreakLine)
        {
            var now = DateTime.Now;
            Debug.Write(now.ToUniversalTime() + ":" + now.Millisecond);
            if (endWithBreakLine)
                Debug.Write("\n");
        }

        public void PrintDate()
        {
            PrintDate(false);
        }

        public virtual void WriteLine(string line)
        {
            lock (this)
            {
                try
                {
                    PrintDate();
                    Debug.WriteLine(String.Format(" - {0}", line));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
        }
    }

    // Singleton
    public class DebugLogger : Logger
    {
        #region Singleton
        private static DebugLogger _instance = null;
        public static new DebugLogger Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new DebugLogger();
                return _instance;
            }
        }
        #endregion

        public bool DebugMode;

        private DebugLogger()
        {
            DebugMode = false;
        }

        public override void WriteLine(string line)
        {
            if (DebugMode)
            {
                base.WriteLine(line);
            }
        }
    }
}
